﻿//
// (C) Copyright 2009 Irantha Suwandarathna (iranthas@hotmail.com)
// All rights reserved.
//

/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 * 
 ********************************************************/


using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using EffiProz.Core;
using EffiProz.Core.Results;
using EffiProz.Core.Errors;


namespace System.Data.EffiProz
{
    public sealed class EfzException : DbException
    {
        private string _sqlState;
        private int _errorCode;
        private Exception _cause;
      
        /// <summary>
        /// Various public constructors that just pass along to the base Exception
        /// </summary>
        /// <param name="message">Passed verbatim to Exception</param>
        public EfzException(string message)
            : base(message)
        {
        }

        // <summary>
        /// Various public constructors that just pass along to the base Exception
        /// </summary>
        /// <param name="message">Passed verbatim to Exception</param>
        public EfzException(string message, string sqlState, int errorCode)
            : base(message)
        {
            _sqlState = sqlState;
            _errorCode = errorCode;
        }

        /// <summary>
        /// Various public constructors that just pass along to the base Exception
        /// </summary>
        public EfzException()
        {
        }

        /// <summary>
        /// Various public constructors that just pass along to the base Exception
        /// <param name="message">Passed to Exception</param>
        /// <param name="innerException">Passed to Exception</param>
        /// </summary>
        public EfzException(string message, Exception innerException)
            : base(message, innerException)
        {
            _cause = innerException;
        }

        public EfzException(string message,string sqlState,int code,  Exception innerException)
            : base(message, innerException)
        {
            _sqlState = sqlState;
            _errorCode = code;
        }



        public static void ThrowError(CoreException e)
        {
            throw new EfzException(e.getMessage(), e.getSQLState(),
                                   e.getErrorCode());
        }

        public static void ThrowError(Result r)
        {
            throw new EfzException(r.getMainString(), r.getSubString(),
                                   r.getErrorCode(), r.getException());
        }

        public static EfzException GetException( CoreException e)
        {
            return new EfzException(e.getMessage(), e.getSQLState(),
                                    e.getErrorCode());
        }

        public static EfzException SqlWarning(Result r)
        {
            return new EfzException(r.getMainString(), r.getSubString(),
                                  r.getErrorCode());
        }

        public static EfzException GetException(int id)
        {
            return GetException(Error.error(id));
        }

        public static EfzException GetException(int id, String message)
        {
            return GetException(Error.error(id, message));
        }

        public static EfzException GetException(int id, int subId, Object[] add)
        {
            return GetException(Error.error(id, subId));
        }

     
    }
}
